package ink.lvxin.datastructure.ch1;

import java.util.ArrayList;
import java.util.List;

public class Recursive {
    private static void printOut(long number) {
        if (number >= 10) {
            printOut(number / 10);
        }

        System.out.print(number % 10);
    }
    private static void printOut2(long number) {
        List<Long> list = new ArrayList<>();
        for (;; number = number / 10) {
            list.add(number % 10);
            if (number < 10 ){
                break;
            }
        }

        for (int i = list.size() - 1; i >= 0; i--) {
            System.out.print(list.get(i));
        }
    }

    public static void main(String[] args){
        long begin = System.currentTimeMillis();
        printOut(1234);
        System.out.println("\nprintOut time cost:" + (System.currentTimeMillis() - begin) + "ms");
        begin = System.currentTimeMillis();
        printOut2(1234);
        System.out.println("\nprintOut2 time cost:" + (System.currentTimeMillis() - begin) + "ms");

        begin = System.currentTimeMillis();
        printOut(43423243);
        System.out.println("\nprintOut time cost:" + (System.currentTimeMillis() - begin) + "ms");
        begin = System.currentTimeMillis();
        printOut2(43423243);
        System.out.println("\nprintOut2 time cost:" + (System.currentTimeMillis() - begin) + "ms");

        begin = System.currentTimeMillis();
        printOut(1111111111111111111L);
        System.out.println("\nprintOut time cost:" + (System.currentTimeMillis() - begin) + "ms");
        begin = System.currentTimeMillis();
        printOut2(1111111111111111111L);
        System.out.println("\nprintOut2 time cost:" + (System.currentTimeMillis() - begin) + "ms");
    }
}
